import request from "@/utils/request";

// const AUTH_BASE_URL = "/api/v1/auth";

const AuthAPI = {
  /** 登录接口*/
  login(data) {
    // const formData = new FormData();
    // formData.append("account", data.account);
    // formData.append("password", data.password);
    // formData.append("key", data.key);
    // formData.append("code", data.code);
    return request({
      url: `/login`,
      method: "post",
      data: data,
    });
  },
  // 登录
  // export const login = data => createAPI(`/login`, 'post', data)

  /** 刷新 token 接口*/
  refreshToken(refreshToken) {
    return request({
      url: `${AUTH_BASE_URL}/refresh-token`,
      method: "post",
      params: { refreshToken: refreshToken },
      headers: {
        Authorization: "no-auth",
      },
    });
  },

  /** 注销登录接口 */
  logout() {
    return request({
      url: `${AUTH_BASE_URL}/logout`,
      method: "delete",
    });
  },

  /** 获取验证码接口*/
  // 获取登录页面验证码图片
  //  getCaptcha = data => createAPI('/captcha' + `?key=${data}`, 'get', data, 'arraybuffer')
  getCaptcha(data) {
    return request({
      url: '/captcha' + `?key=${data}`,
      method: 'get',
      // // GET 请求应该用 params 传递参数，而不是 data
      // params: { key: data },
      responseType: 'arraybuffer'
    });
  },
};

export default AuthAPI; 
